package o;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import o.afv.c;
import o.afv.e;

final class aft extends afq {
    private boolean ˊ;
    private e ˋ;
    private a ˎ;
    private c ˏ;
    private int ॱ;

    static final class a {
        public final int ˊ;
        public final o.afv.a[] ˋ;
        public final c ˎ;
        public final e ˏ;
        public final byte[] ॱ;

        public a(e eVar, c cVar, byte[] bArr, o.afv.a[] aVarArr, int i) {
            this.ˏ = eVar;
            this.ˎ = cVar;
            this.ॱ = bArr;
            this.ˋ = aVarArr;
            this.ˊ = i;
        }
    }

    aft() {
    }

    public static boolean ॱ(anc o_anc) {
        try {
            return afv.ˋ(1, o_anc, true);
        } catch (ParserException e) {
            return false;
        }
    }

    protected void ˏ(boolean z) {
        super.ˏ(z);
        if (z) {
            this.ˎ = null;
            this.ˋ = null;
            this.ˏ = null;
        }
        this.ॱ = 0;
        this.ˊ = false;
    }

    protected void ॱ(long j) {
        boolean z;
        int i = 0;
        super.ॱ(j);
        if (j != 0) {
            z = true;
        } else {
            z = false;
        }
        this.ˊ = z;
        if (this.ˋ != null) {
            i = this.ˋ.ʼ;
        }
        this.ॱ = i;
    }

    protected long ˏ(anc o_anc) {
        int i = 0;
        if ((o_anc.ˏ[0] & 1) == 1) {
            return -1;
        }
        int ॱ = ॱ(o_anc.ˏ[0], this.ˎ);
        if (this.ˊ) {
            i = (this.ॱ + ॱ) / 4;
        }
        ˎ(o_anc, (long) i);
        this.ˊ = true;
        this.ॱ = ॱ;
        return (long) i;
    }

    protected boolean ˎ(anc o_anc, long j, c cVar) throws IOException, InterruptedException {
        if (this.ˎ != null) {
            return false;
        }
        this.ˎ = ˊ(o_anc);
        if (this.ˎ == null) {
            return true;
        }
        List arrayList = new ArrayList();
        arrayList.add(this.ˎ.ˏ.ʽ);
        arrayList.add(this.ˎ.ॱ);
        cVar.ˏ = Format.ˎ(null, "audio/vorbis", null, this.ˎ.ˏ.ˎ, -1, this.ˎ.ˏ.ˊ, (int) this.ˎ.ˏ.ˋ, arrayList, null, 0, null);
        return true;
    }

    a ˊ(anc o_anc) throws IOException {
        if (this.ˋ == null) {
            this.ˋ = afv.ˊ(o_anc);
            return null;
        } else if (this.ˏ == null) {
            this.ˏ = afv.ॱ(o_anc);
            return null;
        } else {
            Object obj = new byte[o_anc.ॱ()];
            System.arraycopy(o_anc.ˏ, 0, obj, 0, o_anc.ॱ());
            o.afv.a[] ˊ = afv.ˊ(o_anc, this.ˋ.ˊ);
            return new a(this.ˋ, this.ˏ, obj, ˊ, afv.ˋ(ˊ.length - 1));
        }
    }

    static int ˏ(byte b, int i, int i2) {
        return (b >> i2) & (255 >>> (8 - i));
    }

    static void ˎ(anc o_anc, long j) {
        o_anc.ॱ(o_anc.ॱ() + 4);
        o_anc.ˏ[o_anc.ॱ() - 4] = (byte) ((int) (j & 255));
        o_anc.ˏ[o_anc.ॱ() - 3] = (byte) ((int) ((j >>> 8) & 255));
        o_anc.ˏ[o_anc.ॱ() - 2] = (byte) ((int) ((j >>> 16) & 255));
        o_anc.ˏ[o_anc.ॱ() - 1] = (byte) ((int) ((j >>> 24) & 255));
    }

    private static int ॱ(byte b, a aVar) {
        if (aVar.ˋ[ˏ(b, aVar.ˊ, 1)].ˎ) {
            return aVar.ˏ.ॱॱ;
        }
        return aVar.ˏ.ʼ;
    }
}
